package com.hundsun.yr.universal.p2p.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.Utils.HeaderMap;
import com.hundsun.yr.universal.library.base.BaseWebActivity;
import com.hundsun.yr.universal.library.common.MD5Utils;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils.NetType;
import com.hundsun.yr.universal.library.utils.RegularUtils;
import com.hundsun.yr.universal.library.widget.HSButton;
import com.hundsun.yr.universal.library.widget.HSEditText;
import com.hundsun.yr.universal.library.widget.HSPassedwordEditText;
import com.hundsun.yr.universal.library.widget.NoScrollViewPager;
import com.hundsun.yr.universal.p2p.HsApplication;

import com.hundsun.yr.universal.p2p.bean.enums.OssidEnum;
import com.hundsun.yr.universal.p2p.config.Constants;
import com.hundsun.yr.universal.p2p.config.Extras;
import com.hundsun.yr.universal.p2p.config.TaskConstants;
import com.hundsun.yr.universal.p2p.datahandler.RegisterValidateHandler;
import com.hundsun.yr.universal.p2p.presenter.base.LoginPresenter;
import com.hundsun.yr.universal.p2p.presenter.impl.LoginPresenterImpl;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;
import com.hundsun.yr.universal.p2p.ui.adapter.BasePagerAdapter;
import com.hundsun.yr.universal.p2p.ui.adapter.SegmentBasePagerAdapter;
import com.hundsun.yr.universal.p2p.utils.BaseRequestTool2;
import com.hundsun.yr.universal.p2p.utils.CommTool;
import com.hundsun.yr.universal.p2p.view.LoginView;
import com.hundsun.yr.universal.p2p.widget.ValidateButton;
import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

import de.greenrobot.event.EventBus;

/**
 * @author tonglj
 */
public class LoginActivity extends BaseActivity implements LoginView, OnClickListener, ViewPager.OnPageChangeListener {
    /**
     * 请求接口
     **/
    private LoginPresenter mPresenter = null;
    /**
     * 友盟API
     */
    private UMShareAPI mShareAPI;
    /**
     * 第三方平台类型
     */
    private SHARE_MEDIA platform;
    /**
     * 授权token
     */
    private String token;
    /**
     * 跳转标识
     */
    private String NAVIGATE_TAG = "";

//    private HSDialog dialog = null;

    /**
     * loan页面跳转标识
     */
    private String LOANFLAG = "";

    /**
     * 关闭
     */
    private ImageView login_close;

    /**
     * 返回上一步
     */
    private ImageView icon_back;

    /**
     * tablayout
     */
    private TabLayout tl_login;

    /**
     * viewpger注册or登陆
     */
    private NoScrollViewPager viewpager_login;

    /**
     * 登陆/注册
     */
    private String[] segments;

    private SegmentBasePagerAdapter adapter;

    private ArrayList<View> viewList;

    /**
     * 快速登录
     */
    private TextView tv_quick_login = null;

    /**
     * 登录item账号
     */
    private HSEditText et_username = null;

    /**
     * 登录Item密码
     */
    private HSPassedwordEditText et_pwd = null;

    /**
     * 登录按钮
     */
    private HSButton btn_login = null;

    /**
     * 注册第一步手机号
     */
    private HSEditText et_register_username = null;

    /**
     * 注册第一步按钮
     */
    private HSButton btn_register_next1 = null;

    /**
     * 第二步输入验证码
     */
    private HSEditText et_register_validate = null;

    /**
     * 验证码按钮
     */
    private ValidateButton btn_register_validate = null;

    /**
     * 密码
     */
    private HSPassedwordEditText et_register_pwd = null;

    /**
     * 邀请人
     */
    private HSEditText et_register_invest_person = null;

    /**
     * 注册第二个下一步
     */
    private HSButton btn_register_next2 = null;

    /**
     * 注册第一步
     */
    private LinearLayout ll_register_step1 = null;

    /**
     * 注册第二步
     */
    private LinearLayout ll_register_step2 = null;
    private String zwgt_data;
    private String TAG = "LoginActivity";
    private String phonetext;

    /**
     * 语音短信
     */
    private TextView tv_register_voice_sms;
    private String validateNum;
    private String passStr;
    private String refereePhone;
    private boolean isSendSmsInStep1 = true;

    /**
     * 登录注册界面
     */
    private LinearLayout ll_login_register = null;

    /**
     * 注册成功界面
     */
    private LinearLayout ll_login_register_success = null;

    /**
     * 开户
     */
    private HSButton btn_open_account = null;

    /**
     * 暂不开户
     */
    private TextView btn_no_open_account = null;

    /**
     * 快速登陆
     */
    private LinearLayout ll_quick_login = null;

    /**
     * 快速登陆
     */
    private HSEditText et_quick_login = null;

    /**
     * 输入验证码
     */
    private HSEditText et_quick_validate = null;

    /**
     * 快速登陆验证码
     */
    private ValidateButton vb_quick_login = null;

    /**
     * 快速登陆
     */
    private TextView tv_login_voice_sms = null;

    /**
     * 快速登陆按钮
     */
    private HSButton btn_quick_login = null;

    /**
     * 快速登陆手机号
     */
    private String mobile;
    private String vCode;

    /**
     * 所在页面记录
     */
    private String PAGEFLAG = "LOGIN";

    private TextView tv_protocol = null;
    private boolean REGISTER_FIRST = false;
    private String where = "";

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return true;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
//        LOANFLAG = extras.getString("LOANFLAG");
//        NAVIGATE_TAG = extras.getString(Extras.NAVIGATE_TAG);
        REGISTER_FIRST = extras.getBoolean("REGISTER_FIRST");
        where = extras.getString("WHERE");
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_login;
    }

    @Override
    protected void onEveComming(@SuppressWarnings("rawtypes") EventCenter eventCenter) {

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected View getLoadingTargetView() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected void initViewsAndEvents() {
        sharedPreferences.clear(mContext);
        findView();


        setToolbarTitle(R.string.login_space);

        mPresenter = new LoginPresenterImpl(this, this);
        mPresenter.initialized();

        View view1 = View.inflate(this, R.layout.item_login, null);
        View view2 = View.inflate(this, R.layout.item_register, null);

        /**
         * 子布局1找控件
         */
        tv_quick_login = findView(view1, R.id.tv_quick_login);
        et_username = findView(view1, R.id.et_username);
        et_pwd = findView(view1, R.id.et_pwd);
        btn_login = findView(view1, R.id.btn_login);


//        et_username.setRightIconVisible(false);
        /**
         * 子控件2找控件
         */
        et_register_username = findView(view2, R.id.et_register_username);
        btn_register_next1 = findView(view2, R.id.btn_register_next1);
        ll_register_step1 = findView(view2, R.id.ll_register_step1);

        btn_register_validate.init(TAG);
        vb_quick_login.init(false, TAG);


        /**
         * 按钮监听
         */
        tv_quick_login.setOnClickListener(this);
        btn_login.setOnClickListener(this);
        login_close.setOnClickListener(this);
        icon_back.setOnClickListener(this);

        btn_register_next1.setOnClickListener(this);
        btn_register_validate.setOnClickListener(this);
        btn_register_next2.setOnClickListener(this);

        btn_open_account.setOnClickListener(this);
        btn_no_open_account.setOnClickListener(this);
        vb_quick_login.setOnClickListener(this);
        tv_login_voice_sms.setOnClickListener(this);
        btn_quick_login.setOnClickListener(this);
        tv_register_voice_sms.setOnClickListener(this);
        tv_protocol.setOnClickListener(this);

        mDataHandler = new RegisterValidateHandler(mContext);


        viewList = new ArrayList<>();
        viewList.add(view1);
        viewList.add(view2);
        //创建PagerAdapter适配器
        BasePagerAdapter adapter = new BasePagerAdapter(viewList);
        // ViewPager加载适配器
        viewpager_login.setAdapter(adapter);

        viewpager_login.addOnPageChangeListener(this);

        if (REGISTER_FIRST) {
            viewpager_login.setCurrentItem(1);
            et_register_username.setFocusable(true);
            et_register_username.setFocusableInTouchMode(true);
            et_register_username.requestFocus();

            this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }

        //viewpager和tablayout绑定
        segments = getResources().getStringArray(R.array.login);
        tl_login.setupWithViewPager(viewpager_login);
        tl_login.getTabAt(0).setText(segments[0]);
        tl_login.getTabAt(1).setText(segments[1]);

        HsApplication.goGesture = false;
        HsApplication.isSrcreenOn = false;

        progressDailog.setText(mContext.getString(R.string.loading));
    }

    /**
     * 初始化第三方登录平台配置
     */
    private void initPlatformConfig() {
        // QQ和QQ空间
        PlatformConfig.setQQZone(mContext.getString(R.string.qq_app_id),
                mContext.getString(R.string.qq_app_key));
        // 新浪微博
        PlatformConfig.setSinaWeibo(mContext.getString(R.string.sina_app_key),
                mContext.getString(R.string.sina_app_secret), "");
    }

    /**
     * 初始化UI
     */
    private void findView() {
        login_close = findView(R.id.login_close);
        icon_back = findView(R.id.icon_back);
        tl_login = findView(R.id.tl_login);
        viewpager_login = findView(R.id.viewpager_login);

        ll_login_register = findView(R.id.ll_login_register);
        ll_login_register_success = findView(R.id.ll_login_register_success);
        btn_open_account = findView(R.id.btn_open_account);
        btn_no_open_account = findView(R.id.btn_no_open_account);

        et_register_validate = findView(R.id.et_register_validate);
        btn_register_validate = findView(R.id.btn_register_validate);
        et_register_pwd = findView(R.id.et_register_pwd);
        et_register_invest_person = findView(R.id.et_register_invest_person);
        btn_register_next2 = findView(R.id.btn_register_next2);
        ll_register_step2 = findView(R.id.ll_register_step2);
        tv_register_voice_sms = findView(R.id.tv_register_voice_sms);

        //快速登陆
        ll_quick_login = findView(R.id.ll_quick_login);
        et_quick_login = findView(R.id.et_quick_login);
        et_quick_validate = findView(R.id.et_quick_validate);
        vb_quick_login = findView(R.id.vb_quick_login);
        tv_login_voice_sms = findView(R.id.tv_login_voice_sms);
        btn_quick_login = findView(R.id.btn_quick_login);
        tv_protocol = findView(R.id.tv_protocol);
    }

    @Override
    protected void onNetworkConnected(NetType type) {
        // TODO Auto-generated method stub
    }

    @Override
    protected void onNetworkDisConnected() {
        // TODO Auto-generated method stub
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return true;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_login://登陆
                try {
                    mPresenter.validateCredentials(et_username.getPhone(), et_pwd.getText());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;

            case R.id.login_close:
                finish();
                break;

            case R.id.tv_quick_login://快速登录
                mPresenter.forgetPwd();
                break;

            case R.id.btn_register_next1:
                isSendSmsInStep1 = true;
                phonetext = et_register_username.getPhone();
                if (TextUtils.isEmpty(phonetext)) {
                    showToast(R.string.toast_checkphone_empty);
                } else if (RegularUtils.isPhoneNum(phonetext)) {
                    getSms(phonetext);
                } else {
                    showToast(R.string.error_phone_number);
                }
                break;

            case R.id.icon_back://返回上一步
                PAGEFLAG = "LOGIN";
                login_close.setVisibility(View.VISIBLE);
                icon_back.setVisibility(View.GONE);
                ll_login_register.setVisibility(View.VISIBLE);
                ll_register_step2.setVisibility(View.GONE);
                ll_login_register_success.setVisibility(View.GONE);
                ll_quick_login.setVisibility(View.GONE);
                break;

            case R.id.btn_register_validate://获取验证码
                isSendSmsInStep1 = false;
                if (TextUtils.isEmpty(phonetext)) {
                    showToast(R.string.toast_checkphone_empty);
                } else if (RegularUtils.isPhoneNum(phonetext)) {
                    getSms(phonetext);
                } else {
                    showToast(R.string.error_phone_number);
                }
                break;
            case R.id.btn_register_next2://注册第二个下一步
                if (checkPass()) {
                    //注册网络逻辑
                    registerUser();
                }
                break;

            case R.id.btn_open_account:
                //跳转开户界面
                readyGo(OpenAccountBankActivity.class);
                break;

            case R.id.btn_no_open_account:
                //暂不开户
                readyGoThenKill(MainActivity.class);
//                finish();
                break;

            case R.id.vb_quick_login://短信验证码
                isSendSmsInStep1 = false;
                mobile = et_quick_login.getPhone();
                //验证手机号
                if (TextUtils.isEmpty(mobile)) {
                    showToast(R.string.empty_phone_number);
                    return;
                }

                if (!RegularUtils.isPhoneNum(mobile)) {
                    showToast(R.string.error_phone_number);
                    return;
                }

                vb_quick_login.setCountdown();

                zwgt_data = BaseRequestTool2.getFormatedDateString();
                JSONObject map2 = new JSONObject();
                try {
                    map2.put("type", "15");
                    map2.put("phone", mobile);
                    map2.put("channel", "0");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                JSONObject jsonParams2 = CommTool.getJSONParams(map2, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);

                mPresenter.loadingData(TaskConstants.TASK_SENDSMS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_SENDSMS, Constants.EVENT_DATA, jsonParams2,
                        BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, getString(R.string.api_index_test) + TaskConstants.TASK_SENDSMS, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);

                break;

            case R.id.tv_login_voice_sms://发送语音短信
                isSendSmsInStep1 = false;
                mobile = et_quick_login.getPhone();
                //验证手机号
                if (TextUtils.isEmpty(mobile)) {
                    showToast(R.string.empty_phone_number);
                    return;
                }

                if (!RegularUtils.isPhoneNum(mobile)) {
                    showToast(R.string.error_phone_number);
                    return;
                }

                zwgt_data = BaseRequestTool2.getFormatedDateString();
                JSONObject map3 = new JSONObject();
                try {
                    map3.put("type", "15");
                    map3.put("phone", mobile);
                    map3.put("channel", "1");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                JSONObject jsonParams3 = CommTool.getJSONParams(map3, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);

                mPresenter.loadingData(TaskConstants.TASK_SENDSMS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_SENDSMS, Constants.EVENT_DATA, jsonParams3,
                        BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, getString(R.string.api_index_test) + TaskConstants.TASK_SENDSMS, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);

                break;

            case R.id.tv_register_voice_sms://发送语音短信
                isSendSmsInStep1 = false;
                phonetext = et_register_username.getPhone();
                //验证手机号
                if (TextUtils.isEmpty(phonetext)) {
                    showToast(R.string.empty_phone_number);
                    return;
                }

                if (!RegularUtils.isPhoneNum(phonetext)) {
                    showToast(R.string.error_phone_number);
                    return;
                }

                zwgt_data = BaseRequestTool2.getFormatedDateString();
                JSONObject map4 = new JSONObject();
                try {
                    map4.put("type", "1");
                    map4.put("phone", phonetext);
                    map4.put("channel", "1");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                JSONObject jsonParams4 = CommTool.getJSONParams(map4, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);

                mPresenter.loadingData(TaskConstants.TASK_SENDSMS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_SENDSMS, Constants.EVENT_DATA, jsonParams4,
                        BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, getString(R.string.api_index_test) + TaskConstants.TASK_SENDSMS, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);

                break;

            case R.id.btn_quick_login://快速登陆
                mobile = et_quick_login.getPhone();
                vCode = et_quick_validate.getText().toString();
                //准备登陆
                //验证手机号
                if (TextUtils.isEmpty(mobile)) {
                    showToast(R.string.empty_phone_number);
                    return;
                }

                if (!RegularUtils.isPhoneNum(mobile)) {
                    showToast(R.string.error_phone_number);
                    return;
                }
                //验证验证码格式
                if (TextUtils.isEmpty(vCode)) {
                    showToast(R.string.empty_vcode);
                    return;
                }

                if (!RegularUtils.isLength(vCode, 6)) {
                    showToast(R.string.error_vcode);
                    return;
                }

                //进行验证码登陆
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                JSONObject map = new JSONObject();
                try {
                    map.put("phone", mobile);
                    map.put("vcode", vCode);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                JSONObject jsonParams = CommTool.getJSONParams(map, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);

                mPresenter.loadingData(TaskConstants.TASK_LOGINBYSMS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_LOGINBYSMS, Constants.EVENT_DATA, jsonParams,
                        BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, getString(R.string.api_index_test) + TaskConstants.TASK_LOGINBYSMS, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);

                break;

            case R.id.tv_protocol://注册协议
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap mHeader = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.h5_protocol) + TaskConstants.TASK_REGISTPROT,
                        "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);
                HeaderMap headerMap = new HeaderMap();
                headerMap.setMap(mHeader);

                Bundle bundle = new Bundle();
                bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, OssidEnum.REGIST_PROTOCOL.getOssLabel());
                bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, mContext.getString(R.string.root_h5_url_test) + getString(R.string.h5_protocol) + TaskConstants.TASK_REGISTPROT);
                bundle.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap);
                bundle.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebProtocolActivity.class, bundle);
                break;
        }
    }

    private void registerUser() {

        zwgt_data = BaseRequestTool2.getFormatedDateString();
        JSONObject map = new JSONObject();
        try {
            map.put("phone", phonetext);
            map.put("passwd", MD5Utils.getMD5String(passStr));
            map.put("code", validateNum);
            map.put("inviter", refereePhone);
            map.put("cp_channel", mContext.getString(R.string.channel));
//            Logs.e("channel: " + CommTool.getChannel(mContext));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        JSONObject jsonParams = CommTool.getJSONParams(map, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);

        mPresenter.loadingData(TaskConstants.TASK_REGISTER, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_index_test)
                + TaskConstants.TASK_REGISTER, Constants.EVENT_DATA, jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_index_test)
                + TaskConstants.TASK_REGISTER, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), true);
    }

    private void getSms(String phonetext) {
        zwgt_data = BaseRequestTool2.getFormatedDateString();
        JSONObject map = new JSONObject();
        try {
            //type=1 注册账号  phone电话号码  channel渠道0短信
            map.put("type", "1");
            map.put("phone", phonetext);
            map.put("channel", "0");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        JSONObject jsonParams = CommTool.getJSONParams(map, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);
        mPresenter.loadingData(TaskConstants.TASK_SENDSMS, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_index_test)
                + TaskConstants.TASK_SENDSMS, Constants.EVENT_DATA, jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST,
                mContext.getString(R.string.api_index_test) + TaskConstants.TASK_SENDSMS, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);
    }

    public void doLogin() {
        mShareAPI = UMShareAPI.get(this);
//        mShareAPI.doOauthVerify(this, platform, umAuthListener);
    }

    /**
     * 获取权限监听，在这里做了验证token事情
     */
//    private UMAuthListener umAuthListener = new UMAuthListener() {
//        @Override
//        public void onComplete(SHARE_MEDIA platform, int action,
//                               Map<String, String> data) {
//            if (null != data) {
//                token = data.get("uid");
//                mPresenter.validateToken(token, platform.name());
//            }
//        }
//
//        @Override
//        public void onError(SHARE_MEDIA platform, int action, Throwable t) {
//            Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_SHORT)
//                    .show();
//        }
//
//        @Override
//        public void onCancel(SHARE_MEDIA platform, int action) {
//            Toast.makeText(getApplicationContext(), "登录取消", Toast.LENGTH_SHORT)
//                    .show();
//        }
//    };
    @Override
    protected void onDestroy() {
        if (null != mShareAPI) {
//            mShareAPI.deleteOauth(this, platform, umAuthListener);
        }
        btn_register_validate.onDestroy();
        vb_quick_login.onDestroy();
        super.onDestroy();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        mShareAPI.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void initializeViews(String username) {
        switch (username) {
            case TaskConstants.TASK_SENDSMS:
                // TODO: 2017/9/12 这边进行数据清楚
                if (isSendSmsInStep1) {
                    btn_register_validate.reset();
                    btn_register_validate.start();

                    et_register_validate.setText("");
                    et_register_pwd.setText("");
                    et_register_invest_person.setText("");


                    login_close.setVisibility(View.GONE);
                    icon_back.setVisibility(View.VISIBLE);

                    ll_login_register.setVisibility(View.GONE);
                    ll_register_step2.setVisibility(View.VISIBLE);
                    ll_login_register_success.setVisibility(View.GONE);
                    ll_quick_login.setVisibility(View.GONE);

                    PAGEFLAG = "REGISTER_STEP2";
                }
                break;

            case TaskConstants.TASK_REGISTER:
                //注册成功
                EventBus.getDefault().post(new EventCenter(Constants.EVENT_REFRESH_DATA));//登陆成功通知某些页面进行数据刷新
                EventBus.getDefault().post(new EventCenter(Constants.EVENT_DATA_LOGIN));//登陆成功通知某些页面进行数据刷新
                EventBus.getDefault().post(new EventCenter(Extras.INVEST_REFRESH));//登陆成功通知某些页面进行数据刷新
                EventBus.getDefault().post(new EventCenter(Extras.REGISTER_SUCCESS));//登陆成功通知某些页面进行数据刷新
                EventBus.getDefault().post(new EventCenter(Extras.MESSAGE));//注册成功刷新消息按钮

//                ll_login_register.setVisibility(View.GONE);
//                ll_register_step2.setVisibility(View.VISIBLE);
//                ll_login_register_success.setVisibility(View.VISIBLE);
//                ll_quick_login.setVisibility(View.GONE);
//
//                login_close.setVisibility(View.VISIBLE);
//                icon_back.setVisibility(View.GONE);

                readyGoThenKill(MainActivity.class);

                PAGEFLAG = "REGISTER_SUCCESS";
                break;

            case TaskConstants.TASK_LOGINBYSMS:

                break;
        }
    }

    @SuppressWarnings("rawtypes")
    @Override
    public void navigateToHomePage() {
        EventBus.getDefault().post(new EventCenter(Constants.EVENT_REFRESH_DATA));//登陆成功通知某些页面进行数据刷新

        EventBus.getDefault().post(new EventCenter(Extras.INVEST_REFRESH));//登陆成功通知某些页面进行数据刷新
        EventBus.getDefault().post(new EventCenter(Extras.MESSAGE));//登陆成功刷新消息按钮

        if ("WebNewsShareActivity".equals(where)) {
            finish();
        } else {
            EventBus.getDefault().post(new EventCenter(Constants.EVENT_DATA_LOGIN));//通知刷到我的页面
            readyGoThenKill(MainActivity.class);
        }
    }

    /**
     * 联合登录注册
     */
    @Override
    public void navigateToJointRegiester() {
//        Bundle bundle = new Bundle();
//        bundle.putString(UserInfo.TOKEN, token);
//        bundle.putString(UserInfo.JOINT_TYPE, platform.name());
//        readyGo(JointLoginInputPhoneActivity.class, bundle);
    }

    @Override
    public void navigateToRegiester() {
        // TODO Auto-generated method stub
        readyGo(RegisterInputPhoneActivity.class);
    }

    @Override
    public void navigateForgetPassword() {
        ll_login_register.setVisibility(View.GONE);
        ll_register_step2.setVisibility(View.GONE);
        ll_login_register_success.setVisibility(View.GONE);
        ll_quick_login.setVisibility(View.VISIBLE);
        login_close.setVisibility(View.GONE);
        icon_back.setVisibility(View.VISIBLE);

        PAGEFLAG = "QUICKLOGIN";
    }

    @Override
    public void showValidateError(String error) {
        // TODO Auto-generated method stub
        showToast(error);
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == event.KEYCODE_BACK) {
            if (TextUtils.equals(PAGEFLAG, "QUICKLOGIN") || TextUtils.equals(PAGEFLAG, "REGISTER_STEP2")) {
                login_close.setVisibility(View.VISIBLE);
                icon_back.setVisibility(View.GONE);
                ll_login_register.setVisibility(View.VISIBLE);
                ll_register_step2.setVisibility(View.GONE);
                ll_login_register_success.setVisibility(View.GONE);
                ll_quick_login.setVisibility(View.GONE);
                PAGEFLAG = "LOGIN";
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
//        if (position == 1){
//            ll_register_step1.setVisibility(View.VISIBLE);
//            ll_register_step2.setVisibility(View.GONE);
//
//            login_close.setVisibility(View.VISIBLE);
//            icon_back.setVisibility(View.GONE);
//        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    /**
     * 输入框校验
     *
     * @return
     */
    private boolean checkPass() {
        validateNum = CommTool.getValue(et_register_validate);
        passStr = CommTool.getValue(et_register_pwd);
        refereePhone = et_register_invest_person.getPhone();
        if (TextUtils.isEmpty(validateNum)) {
            showToast(R.string.validate_emptycheck);
        } else if (TextUtils.isEmpty(passStr)) {
            showToast(R.string.register_pass_emptycheck);
        } else if (validateNum.length() < 6) {
            showToast(R.string.validate_rightcheck);
        } else if (!CommTool.checkPwd(passStr)) {
            showToast(R.string.register_pass_rightcheck);
        } /*else if (!ck_agree.isChecked()) {
            showToast(getString(R.string.tips_agree_protocol, OssidEnum.REGIST_PROTOCOL.getOssLabel()));
        }*/ else if (refereePhone.length() == 0 || CommTool.checkMobile(refereePhone)) {
            return true;
        } else {
            showToast(R.string.refereePhone_rightcheck);
        }

        return false;
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("LoginActivity");
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("LoginActivity");
        MobclickAgent.onPause(this);
    }
}
